package com.mj.mafeed.activity;

import com.mj.mafeed.R;
import com.mj.mafeed.bean.OrderJSON;
import com.mj.mafeed.util.SPUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 支付
 * @author zhaominglei
 * @date 2014-12-30
 * 
 */
@SuppressWarnings("unused")
public class PayActivity extends Activity implements OnClickListener {
	private static final String TAG = PayActivity.class.getSimpleName();
	
	private ImageView goHome;
	private TextView payOrderPrice;
	private OrderJSON orderJSON; 
	private double total = 0.0d; //总计金额
	private String referer; //来自那个链接
	private String username; //用户名
	private String sign; //签名
	private Intent intent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pay);
		
		init();
	}
	
	private void init() {
		goHome = (ImageView)findViewById(R.id.pay_gohome);
		payOrderPrice = (TextView) findViewById(R.id.pay_order_price);
		goHome.setOnClickListener(this);
		
		referer = getIntent().getStringExtra("referer");
		username = (String)SPUtils.get(getApplicationContext(), "username", "");
		sign = (String)SPUtils.get(getApplicationContext(), "sign", "");
		orderJSON = (OrderJSON)getIntent().getSerializableExtra("orderJSON");
		if (orderJSON != null) {
			for (OrderJSON.OrderItem orderItem : orderJSON.getOrderItems()) {
				total += orderItem.getPrice().doubleValue()*orderItem.getQuantity();
			}
			payOrderPrice.setText(String.valueOf(total));
		}
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.pay_gohome:
			intent = new Intent(PayActivity.this, MainActivity.class);
			intent.putExtra("referer", "PayActivity");
			startActivity(intent);
			finish();
			break;

		default:
			break;
		}
	}

	@Override
	public void onBackPressed() {
		intent = new Intent(PayActivity.this, MainActivity.class);
		intent.putExtra("referer", "PayActivity");
		startActivity(intent);
		finish();
	}
}
